package server;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author sxnan
 * @className Request
 * @description TODO
 * @date 2020/7/21
 */
public class Request {

    private InputStream inputStream;
    private String method;//请求方法，例如GET/POST
    private String url;//请求地址，例如/，/index.html

    public Request() {
    }

    public Request(InputStream inputStream) throws IOException {
        this.inputStream = inputStream;
        int count = 0;
        while (count==0){
            count = inputStream.available();
        }
        byte[] bytes = new byte[count];
        inputStream.read(bytes);
        String inputStr = new String(bytes);
        String s = inputStr.split("\\n")[0];
        String[] split = s.split(" ");
        this.method=split[0];
        this.url=split[1];
        System.out.println("=============>>>请求信息为："+new String(bytes));
    }

    public InputStream getInputStream() {
        return inputStream;
    }

    public void setInputStream(InputStream inputStream) {
        this.inputStream = inputStream;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }
}
